<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>图书审核</title>
    <script type="text/javascript" src="../static/jquery-easyui-1.5.5/jquery.min.js"></script>
    <link rel="stylesheet" type="text/css" href="../static/jquery-easyui-1.5.5/themes/bootstrap/easyui.css">
    <link rel="stylesheet" type="text/css" href="../static/jquery-easyui-1.5.5/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="../static/toastr/toastr.min.css">
    <script type="text/javascript" src="../static/jquery-easyui-1.5.5/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../static/jquery-easyui-1.5.5/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="../static/js/book/manage.js"></script>
    <script type="text/javascript" src="../static/js/custom.js"></script>
    <script type="text/javascript" src="../static/toastr/toastr.min.js"></script>
    <script type="text/javascript" src="../static/js/validate.js"></script>
</head>
<body style="margin: 0; padding: 10px;">
<script type="text/javascript">
    /* 计算窗口高度  */
    var h = document.documentElement.clientHeight || document.body.clientHeight;
    
    function formatBookIsbn(value,row,index) {
		return row.book.isbn;
	};
	
    function formatBookName(value,row,index) {
        return row.book.name;
    };
    
    function formatSysUserName(value,row,index) {
        return row.sysUser.name;
    };
    
    function formatState(value,row,index) {
		if(value == 1) {
			return "待审核";
		};
		if(value == 2) {
			return "借阅中";
		};
		if(value == 3) {
			return "已还书";
		}
		
	}

    console.log(h);
    $(function() {
        $('#xtable').datagrid({
            /* 标题文字 */
            title: '借阅管理',
             /* 指明哪一个字段是标识字段 */
            idField: 'id',
            /* 是否显示斑马线效果 */
            striped: true,
            /* 在从远程站点加载数据的时候显示提示消息 */
            loadMsg: '正在加载数据',
            /* 一个URL从远程站点请求数据 */
            url: 'list.do',
            /* 如果为true，则在DataGrid控件底部显示分页工具栏 */
            pagination: true,
            /* 如果为true，则显示一个行号列 */
            rownumbers: true,
            /* 如果为true，则只允许选择一行 */
            singleSelect: true,
            /* 使列自动展开/收缩到合适的DataGrid宽度 */
            fitColumns: true,
            /* fit: true, */
            height: h-29,
            method: 'POST',
            pageSize: 10,
            pageList: [5,10,25,50,100],
            sortName: 'id',
            sortOrder: 'asc',
            queryParams: {
            	state: '2'
            },
            /* 冻结列  */
            frozenColumns: [ [
                {field: 'book.isbn', title: 'ISBN', width: 150, formatter: formatBookIsbn}
            ] ],
            columns: [ [
                {field: 'id', title: 'ID', sortable:true, order: 'asc', hidden: true},
                /* {field: 'isbn', title: 'ISBN', width: 130}, */
                
                {field: 'book.name', title: '书名', width: 100, formatter: formatBookName},
                {field: 'sysUser.name', title: '借阅人', width: 100, formatter: formatSysUserName},
                {field: 'startTime', title: '申请借阅时间', width: 100},
                {field: 'middleTime', title: '审批时间', width: 100},
                {field: 'finishTime', title: '还书时间', width: 100},
                {field: 'state', title: '状态', width: 100, formatter: formatState}
            ] ],
            dialog:{
                create: {
                    title : '新增老师' ,
                    width : 300
                },
                update: {
                    title: '修改信息',
                    width: 300
                }
            } ,
            toolbar: [
                {
                    text: '还书' ,
                    iconCls: 'icon-ok',
                    handler: function(){
                        var $table=$(this).parent().closest('.panel').find('.datagrid-f');
                        var row=$table.datagrid('getSelected');
                        if(row==null){
                            $.messager.alert({
                                title: '提示' ,
                                msg: '请先选中一行，再进行操作！' ,
                                icon : 'info'
                            });
                            return ;
                        }
                        $.messager.confirm('确认对话框', '您想要帮他还书吗？', function(r){
                            if(r){
                                $.post('end',{id:row.id},function(result){
                                    if(result.success){
                                        /*$.messager.show({
                                            title: '提示',
                                            msg: result.msg,
                                            icon: 'info' 
                                        });*/
                                        toastr.warning(result.msg);
                                        /*toastr.success(result.msg);*/
                                        if($table.data('treegrid')){
                                            $table.treegrid('reload');
                                            $table.treegrid('uncheckAll');
                                        }else{
                                            $table.datagrid('reload');
                                            $table.datagrid('uncheckAll');
                                        }
                                    }else{
                                        /*$.messager.alert({
                                            title:'提示',
                                            msg: result.msg,
                                            icon: 'error'
                                        });*/
                                        toastr.error(result.msg);
                                    }
                                });
                            }
                        }); 
                    }
                }, '-',
                $.crudgrid.buttons.reload]

        });
    });
</script>
<table id="xtable">

</table>
</body>
</html>